using System;
using System.Collections.Generic;

namespace ConsoleApplication
{
    public static class Container
    {
        private static readonly IDictionary<Type, Type> _types = new Dictionary<Type, Type>();
        private static readonly IDictionary<Type, dynamic> _typeObjects = new Dictionary<Type, dynamic>();

        public static void RegisterInstance(Type key, dynamic value)
        {
            if (value is Type)
            {
                _types.Add(key, value);
            }
            else
            {
                _typeObjects.Add(key, value);
            }
        }

        public static dynamic GetInstance<TType>()
        {
            dynamic obj = null;

            foreach (var t in _types)
            {
                if (typeof(TType).FullName == t.Key.FullName)
                    obj = Activator.CreateInstance(t.Value);
            }

            if (obj == null)
            {
                foreach (var t in _typeObjects)
                {
                    if (typeof(TType).FullName == t.Key.FullName)
                        obj = t.Value;
                }
            }

            return obj;
        }
    }
}